//
//  UIBarButtonItem+Category.m
//  GJNK
//
//  Created by xmdfst on 16/10/14.
//  Copyright © 2016年 LYX. All rights reserved.
//

#import "UIBarButtonItem+Category.h"

@implementation UIBarButtonItem (Category)


+(id)itemWithTitleWithTitle:(NSString*)title target:(nullable id)target action:(nullable SEL)action isLeft:(BOOL)isLeft
{
    CGRect rect = [YXFrame getStringFrame:title font:FONT(15) width:2000];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, rect.size.width+10, 40)];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleColor:[YXColor textHeavyGray] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = FONT(15);
    if (isLeft) {
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }else{
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    }
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    return item;
}

+(id)itemWithImage:(UIImage *)image target:(id)target action:(SEL)action
{
    return [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:target action:action];
}


@end
